package cn.exrick.xboot.modules.commonlyUsed.serviceimpl;

import cn.exrick.xboot.modules.commonlyUsed.dao.mapper.CommonlyUsedMapper;
import cn.exrick.xboot.modules.commonlyUsed.dto.CommonlyDTO;
import cn.exrick.xboot.modules.commonlyUsed.entity.CommonlyUsed;
import cn.exrick.xboot.modules.commonlyUsed.entity.OrgCommonly;
import cn.exrick.xboot.modules.commonlyUsed.service.ICommonlyUsedService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 常用功能接口实现
 * @author XBW
 */
@Slf4j
@Service
@Transactional
public class ICommonlyUsedServiceImpl extends ServiceImpl<CommonlyUsedMapper, CommonlyUsed> implements ICommonlyUsedService {

    @Autowired
    private CommonlyUsedMapper commonlyUsedMapper;

    @Override
    public List<CommonlyUsed> commonlyList(CommonlyDTO commonlyDTO) {

        LambdaQueryWrapper<CommonlyUsed> queryWrapper = new LambdaQueryWrapper<>();
        if(commonlyDTO.getIsOpen() != null){
            queryWrapper.eq(CommonlyUsed::getIsOpen, 1);
            List<CommonlyUsed> commonlyList = commonlyUsedMapper.selectList(queryWrapper);
            return commonlyList;
        }

        return commonlyUsedMapper.selectList(queryWrapper);

    }

    @Override
    public void deleteCommonly(String id) {
        commonlyUsedMapper.deleteCommonly(id);
    }
}